function formatDate(date) {;
    var year = date.getFullYear();       //年
    var month = date.getMonth() + 1;     //月
    var day = date.getDate();            //日
    return year + "-" + month + "-" + day;
}
function downfile(url) {
    url = url.replace(/-/g, '\\');
    url = "http://" + window.location.host + url.substring(url.indexOf('/'));
    window.open(url);

}

////当前时间加五天.
//var newDate = DateAddORSub("d", "+", 5);
//alert(newDate.toLocaleDateString());
////当前时间减五天.
//newDate = DateAddORSub("d", "-", 5);
//alert(formatDate(newDate));
////当前时间加两个月.
//newDate = DateAddORSub("m", "+", 2);
//alert(newDate.toLocaleDateString());
////当前时间减两个月.
//newDate = DateAddORSub("m", "-", 2);
//alert(formatDate(newDate));
////当前时间加一年
//newDate = DateAddORSub("y", "+", 1);
//alert(newDate.toLocaleDateString());
////当前时间减一年
//newDate = DateAddORSub("y", "-", 1);
//alert(formatDate(newDate));



//s获取当前日期时间“yyyy-MM-dd HH:MM:SS”
//获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
}

function DateAddORSub(interval, type, number) {
    /*
     * 功能:实现Script的Date加减功能.
     * 参数:interval,字符串表达式，表示要添加的时间间隔.
     * 参数:number,数值表达式，表示要添加的时间间隔的个数.
     * 参数:type,加减类型.
     * 返回:新的时间对象.
     * var newDate =DateAddORSub("d","+",5);
     */
    var date = new Date();
    switch (interval) {
        case "y": {
            if (type == "+") {
                date.setFullYear(date.getFullYear() + number);
            } else {
                date.setFullYear(date.getFullYear() - number);
            }
            return date;
            break;
        }
        case "q": {
            if (type == "+") {
                date.setMonth(date.getMonth() + number * 3);
            } else {
                date.setMonth(date.getMonth() - number * 3);
            }
            return date;
            break;
        }
        case "m": {
            if (type == "+") {
                date.setMonth(date.getMonth() + number);
            } else {
                date.setMonth(date.getMonth() - number);
            }
            return date;
            break;
        }
        case "w": {
            if (type == "+") {
                date.setDate(date.getDate() + number * 7);
            } else {
                date.setDate(date.getDate() - number * 7);
            }
            return date;
            break;
        }
        case "d": {
            if (type == "+") {
                date.setDate(date.getDate() + number);
            } else {
                date.setDate(date.getDate() - number);
            }
            return date;
            break;
        }
        case "h": {
            if (type == "+") {
                date.setHours(date.getHours() + number);
            } else {
                date.setHours(date.getHours() - number);
            }
            return date;
            break;
        }
        case "m": {
            if (type == "+") {
                date.setMinutes(date.getMinutes() + number);
            } else {
                date.setMinutes(date.getMinutes() - number);
            }
            return date;
            break;
        }
        case "s": {
            if (type == "+") {
                date.setSeconds(date.getSeconds() + number);
            } else {
                date.setSeconds(date.getSeconds() - number);
            }
            return date;
            break;
        }
        default: {
            if (type == "+") {
                date.setDate(d.getDate() + number);
            } else {
                date.setDate(d.getDate() - number);
            }
            return date;
            break;
        }
    }
}

/*--处理T的时间字符串-*/
function dateTimeStr_Manage(dateTimeStr) {


    //2015-10-12T12:04

    return dateTimeStr.substr(0, 18).replace("T", " ").replace(/-/g, "/");


}

//拼接html的时候的时候特殊字符替换
function escapeHtml(string) {
    var entityMap = {
        "&": "&amp;",
        "<": "&lt;",
        ">": "&gt;",
        '"': '&quot;',
        "'": '&#39;',
        "/": '&#x2F;'
    };
    return String(string).replace(/[&<>"'\/]/g, function (s) {
        return entityMap[s];
    });
}

//重置linkbutton的文本
//id：linkbutton的ID
//text：需要替换的文本
function SetLinkButtonText(id, text) {
    $("#" + id + " span .l-btn-text").html(text);
}

//easyui数字排序
function numberSort(a, b) {
    if (a.length > b.length)
        return 1;
    else if (a.length < b.length)
        return -1;
    else if (a > b)
        return 1;
    else return -1;
}

//easyui 中文排序
function strSort(a, b) {
    return a.localeCompare(b);
}
//获取系统当前时间到精确到日期
function getNowDate_Day() {
    var nowDate = new Date();
    var year = nowDate.getFullYear();
    var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1)
        : nowDate.getMonth() + 1;
    var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate
        .getDate();
    var dateStr = year + "-" + month + "-" + day;

    return dateStr;

}

$(function () {
    $('body').append("<div id=\"myWindow\" class=\"easyui-dialog\" data-options=\"iconCls:'icon-window'\"  closed=\"true\"></div>");
});

function showMyWindow1(title, href, width, height, modal, minimizable, maximizable) {
    $('#myWindow').window(
        {
            title: title,
            width: width === undefined ? 600 : width,
            height: height === undefined ? 400 : height,
            content: '<iframe scrolling="yes" name="iFrame" id="iFrame" frameborder="0"  src="'
                + href
                + '" style="width:100%;height:98%;"></iframe>',
            modal: modal === undefined ? true : modal,
            minimizable: minimizable === undefined ? false
                : minimizable,
            maximizable: maximizable === undefined ? false
                : maximizable,
            shadow: true,
            cache: false,
            closed: false,
            collapsible: false,
            resizable: true,
            draggable: true,

            left: 250,
            top: 150,
            loadingMessage: '正在加载数据，请稍等片刻......'
        });
    //document.getElementById("swicthStyle").href = "../themes/cupertino/easyui.css";
}
//加载时自动最大化
function showMaxWindow(title, href, width, height, modal, minimizable, maximizable, Isfit) {
    $('#myWindow').window(
        {
            title: title,
            width: width === undefined ? 600 : width,
            height: height === undefined ? 400 : height,
            content: '<iframe scrolling="yes" name="iFrame" id="iFrame" frameborder="0"  src="'
                + href
                + '" style="width:100%;height:98%;"></iframe>',
            modal: modal === undefined ? true : modal,
            minimizable: minimizable === undefined ? false
                : minimizable,
            maximizable: maximizable === undefined ? false
                : maximizable,
            shadow: true,
            cache: false,
            closed: false,
            collapsible: false,
            resizable: false,
            draggable: false,
            fit: Isfit,
            left:5,
            top: 0,
            loadingMessage: '正在加载数据，请稍等片刻......'
        });
    //document.getElementById("swicthStyle").href = "../themes/cupertino/easyui.css";
}

function showMyWindow(title, href, width, height, modal, minimizable, maximizable, icon) {
    $('#myWindow').window(
        {
            title: title,
            width: width === undefined ? 600 : width,
            height: height === undefined ? 400 : height,
            content: '<iframe scrolling="yes" name="iFrame" id="iFrame" frameborder="0"  src="'
                + href
                + '" style="width:100%;height:98%;"></iframe>',
            modal: modal === undefined ? true : modal,
            minimizable: minimizable === undefined ? false
                : minimizable,
            maximizable: maximizable === undefined ? false
                : maximizable,
            shadow: true,
            cache: false,
            closed: false,
            collapsible: false,
            resizable: true,
            draggable: true,
            left: null,
            top: null,
            iconCls: icon,
            loadingMessage: '正在加载数据，请稍等片刻......'
        });
    //document.getElementById("swicthStyle").href = "../themes/cupertino/easyui.css";
}

function CloseDialogWin() {
    window.parent.$('#myWindow').dialog('close');
}
function RefreshParentWin(btnId) {
    window.parent.$('#' + btnId).click();
    //  RefreshHomeWin(btnId);
}

//更新首页内容
function RefreshHomeWin(btnId) {
    var PreparentHome = window.parent.parent.frames[0];
    if (PreparentHome != null)
        PreparentHome.$('#' + btnId).click();
}

function CloseParent() {
    var url = "./Index.aspx";
    var parentparentparent = window.parent.parent.parent;
    if (parentparentparent != null) {
        parentparentparent.location.replace(url);
    }
    else {
        var parentparent = window.parent.parent;
        if (parentparent != null) {
            parentparent.location.replace(url);
        }
        else {
            var parent = window.parent;
            if (parent != null) {
                parent.location.replace(url);
            }
            else {
                window.location.replace(url);
            }
        }
    }
}

function GoToErrorPage(ErrorCode) {
    var url = "../SharePages/error.html?ErrorCode=" + ErrorCode;
    var parentparentparent = window.parent.parent.parent;
    if (parentparentparent != null) {
        parentparentparent.location.replace(url);
    }
    else {
        var parentparent = window.parent.parent;
        if (parentparent != null) {
            parentparent.location.replace(url);
        }
        else {
            var parent = window.parent;
            if (parent != null) {
                parent.location.replace(url);
            }
            else {
                window.location.replace(url);
            }
        }
    }
}
//combox绑定年
//ID:combox的ID
function SetYear(id) {
    var time = new Date();
    var year = time.getFullYear();

    var str3 = "[{\"id\":\"" + year + "\",\"text\":\"" + year + "\",\"selected\":\"true\"}";

    for (var i = 1; i < 50; i++) {
        str3 += ",{\"id\":\"" + (year - i) + "\",\"text\":\"" + (year - i) + "\"}";
    }

    str3 += "]";

    $("#" + id).combobox({
        valueField: 'id',
        textField: 'text',
        data: eval('(' + str3 + ')')
    });

}

//combox绑定年
//ID:combox的ID
function BindYearBySearch(id, isshow) {
    var time = new Date();
    var year = time.getFullYear();
    var str3;
    if (isshow) {
        str3 = "[{\"id\":\"-1\",\"text\":\"全部\",\"selected\":\"true\"}";

        for (var i = 0; i < 50; i++) {
            str3 += ",{\"id\":\"" + (year - i) + "\",\"text\":\"" + (year - i) + "\"}";
        }
    } else {
        str3 = "[{\"id\":\"" + year + "\",\"text\":\"" + year + "\",\"selected\":\"true\"}";

        for (var i = 1; i < 50; i++) {
            str3 += ",{\"id\":\"" + (year - i) + "\",\"text\":\"" + (year - i) + "\"}";
        }
    }

    str3 += "]";

    $("#" + id).combobox({
        valueField: 'id',
        textField: 'text',
        data: eval('(' + str3 + ')')
    });

}

//创建table的title
//tableid:table的ID
//title:table的标题
//isVisible：是否显示展开收缩按钮
function CreateTableTitle(tableid, title, isVisible) {

    var guid = uuid();

    var str = "<div class=\"table-header\" >";
    str += "<div style=\"position:relative; width:150px; padding-left:18px; float:left; font-size:12px; font-weight:bold;\" >";
    str += "<i style=\"background:url('../Images/Common/table.png') no-repeat;width:16px; height:16px; display:inline-block; position:absolute; top:6px; left:0px;\"></i>" + title;
    str += "</div><div class=\"table-title-right\" style=\"float:right; right:0px; width:100px; text-align:right; padding-right:5px; position:relative;\">";

    if (isVisible)
        str += "<a id=\"" + guid + "\" href=\"#\" class=\"table-collapse\" style=\" position:absolute; top:6px; right:5px;\"></a>";

    str += "</div></div>";

    $("#" + tableid).before(str);

    if (isVisible) {
        $("#" + guid).bind("click", function () {
            if ($("#" + tableid).is(":visible")) {
                $("#" + guid).attr("class", "table-expand");
                $("#" + tableid).fadeOut("slow");
            } else {
                $("#" + guid).attr("class", "table-collapse");
                $("#" + tableid).fadeIn("slow");
            }

        });
    }

}
function uuid() {

    var s = [];

    var hexDigits = "0123456789abcdef";

    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }

    s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010

    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01

    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");

    return uuid;

}

function GetGUID() {

    var s = [];

    var hexDigits = "0123456789abcdef";

    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }

    s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010

    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01

    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");

    return uuid.toUpperCase();

}

function FormatDateToString(value, format) {

    if (value == null || value == "null")
        return "";

    if (strTrim(value).length == 0)
        return "";

    if (value.indexOf("T") > 0) {
        value = value.replace("T", " ");
    }
    if (value.indexOf(".") > 0) {
        value = value.substring(0, value.indexOf("."));
    }

    return new Date(Date.parse(value.replace(/-/g, "/"))).Format(format);
}

function FormatNumber(value, format) {
    if (value == "" || value == '')
        return 0;
    return Number(Number(value).toFixed(format));
}

function FormatNumberToString(value, format) {
    if (value == "" || value == '')
        return 0;
    return Number(value).toFixed(format);
}

function ConvertToString(value) {
    if (value == "null" || value == null)
        return "";
    else
        return value;
}

//检查类型是textbox的数据
//requiredID:必填项的classname
//controlID:textbox的ID
//message:信息
//len:文本框最多能输入的长度
function CheckTextBoxData(requiredName, controlID, message, len) {

    if (strTrim($("#" + controlID).textbox("getText")).length == 0) {
        var $parent = $("#" + controlID).parent();
        $parent.append("<span class=\"formtips onError\">" + message + "不能为空</span>");
    }
    else {
        if (strTrim($("#" + controlID).textbox("getText")).length > len) {
            var $parent = $("#" + controlID).parent();
            $parent.append("<span class=\"formtips onError\">长度不能超" + len + "过位</span>");
        }
    }
}

//检查类型是combobox的数据
//requiredID:必填项的classname
//controlID:textbox的ID
//message:信息
function CheckComboboxData(requiredName, controlID, message) {
    if (strTrim($("#" + controlID).combobox("getValue")) == "" || strTrim($("#" + controlID).combobox("getValue")) == "-1") {
        var $parent = $("#" + controlID).parent();
        $parent.append("<span class=\"formtips onError\">请选择" + message + "</span>");
    }
}


//清除验证中产生的classname
function ClearCheckClassName(requiredName) {
    $("." + requiredName).parents().find(".formtips").remove();
}

//检查错误信息
function GetCheckMessage() {
    var numError = $('form .onError').length;

    if (numError)
        return false;
    else
        return true;
}

//检查数据，错误信息添加在一个字符串里
function CheckTextBoxDataAddStr(Errormsg, controlID, titleMsg, len) {

    if (strTrim($("#" + controlID).textbox("getText")).length == 0) {
        Errormsg += titleMsg + "不能为空<br>";
    }
    else {
        if (strTrim($("#" + controlID).textbox("getText")).length > len) {
            Errormsg += titleMsg + "长度不能超" + len + "过位<br>";
        }
    }

    return Errormsg;

}



function strTrim(str) {
    return str.replace(/(^\s*)|(\s*$)/g, "");
}